<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-calendar"></i> 订单管理
                </el-breadcrumb-item>
                <el-breadcrumb-item>代练订单</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-row>
                    <el-col :span="3">
                        <el-date-picker v-model="query.start_time" type="datetime" placeholder="开始时间">
                        </el-date-picker>
                    </el-col>
                    <el-col :span="3">
                        <el-date-picker v-model="query.end_time" type="datetime" placeholder="结束时间">
                        </el-date-picker>
                    </el-col>
                    <!-- <el-col :span="3" style="margin-left: 3%">
                        <el-select v-model="query.sort" placeholder="选择排序方式">
                            <el-option key="1" label="最新" value="1"></el-option>
                            <el-option key="2" label="正常" value="2"></el-option>
                        </el-select>
                    </el-col> -->
                    <el-col :span="3">
                        <el-select v-model="query.dailian_status" placeholder="状态" class="handle-select mr10">
                            <el-option label="全部状态" value=""></el-option>
                            <el-option :key="0" label="待支付" :value="0"></el-option>
                            <el-option :key="1" label="待接单" :value="1"></el-option>
                            <el-option :key="2" label="打手待支付" :value="2"></el-option>
                            <el-option :key="3" label="进行中" :value="3"></el-option>
                            <el-option :key="4" label="待确认" :value="4"></el-option>
                            <el-option :key="5" label="售后" :value="5"></el-option>
                            <el-option :key="8" label="已取消" :value="8"></el-option>
                            <el-option :key="9" label="已完成" :value="9"></el-option>
                        </el-select>
                    </el-col>

                    <el-col :span="4" style="margin-left: 6%;display: flex;">
                        <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                        <el-button type="primary"
                            @click="query.status = ''; query.start_time = ''; query.end_time = ''; query.sort == 1">重置</el-button>
                        <el-button type="primary" icon="el-icon-download" @click="exportSource">导出数据</el-button>
                    </el-col>
                </el-row>
            </div>
            <el-table id="repottable" :data="tableData" border v-loading="loading" class="table" ref="multipleTable"
                header-cell-class-name="table-header" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="id" label="ID" sortable width="55" align="center"></el-table-column>
                <el-table-column prop="order_sn" label="订单编号" width="150" align="center"></el-table-column>
                <el-table-column label="用户" prop="mobile" align="center"></el-table-column>
                <el-table-column label="状态" align="center">
                    <template slot-scope="scope">{{ getDailianStatusName(scope.row.dailian_status) }}</template>
                </el-table-column>
                <el-table-column label="支付方式" align="center">
                    <template slot-scope="scope">{{ scope.row.pay_type }}</template>
                </el-table-column>
                <el-table-column label="代练游戏" align="center">
                    <template slot-scope="scope">
                        <el-image class="table-td-thumb" :src="scope.row.goods_info.banner"></el-image>
                        <span>{{ scope.row.goods_info.name }}</span>
                    </template>
                </el-table-column>
                <!--<el-table-column prop="price" label="金额"></el-table-column>-->
                <el-table-column prop="total_price" label="订单总价"></el-table-column>
                <el-table-column prop="pay_price" label="实际付款"></el-table-column>
                <el-table-column prop="red_price" label="红包优惠"></el-table-column>
                <el-table-column prop="created_at" label="创建时间"></el-table-column>
                <el-table-column prop="pay_at" label="支付时间"></el-table-column>
                <el-table-column prop="finish_at" label="完成时间"></el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-edit"
                            @click="InfoView(scope.$index, scope.row)">查看明细</el-button>

                        <el-button v-if="scope.row.dailian_status == 5" type="text"
                            @click="InfoView(scope.$index, scope.row, true)">售后跟进</el-button>
                    </template>


                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination background layout="total, prev, pager, next,sizes"
                    :page-sizes="[0, 10, 20, 50, 100, 500, 1000]" @size-change="handleSizeChange"
                    :current-page="query.page" :page-size="query.pageSize" :total="pageTotal"
                    @current-change="handlePageChange"></el-pagination>
            </div>
        </div>
        <el-dialog :title="'订单详细信息'" v-dialogDrag :visible.sync="InfoVisible"
            :width="followDialogFromBtn ? '98%' : '90%'" :top="followDialogFromBtn ? '2vh' : '5vh'">
            <el-form ref="edit" :model="order_info" label-width="120px">
                <el-row :gutter="24">
                    <el-col :span="8"><span class="gl_t">创建时间：</span>{{ order_info.created_at }}</el-col>
                    <el-col :span="8"><span class="gl_t">开始时间：</span>{{ order_info.created_at }}</el-col>
                    <el-col :span="8"><span class="gl_t">结束时间：</span>{{ order_info.end_at }}</el-col>
                    <el-col :span="8" v-if="order_info.belong == 1"><span
                            class="gl_t">租赁总时长：</span>{{ order_info.num }}小时</el-col>
                    <el-col :span="8"><span class="gl_t">支付时间：</span>{{ order_info.pay_at }}</el-col>
                    <el-col :span="8"><span class="gl_t">完成时间：</span>{{ order_info.finish_at }}</el-col>
                    <el-col :span="8"><span class="gl_t">支付方式：</span>{{ order_info.pay_type }}</el-col>
                    <el-col :span="8"><span class="gl_t">关联游戏：</span>{{ order_info.game_name }}</el-col>
                    <el-col :span="8" v-if="order_info.belong == 1">
                        <span class="gl_t">关联商品：</span>{{ order_info.goods_info.name }}，单价：￥{{ order_info.price }}
                    </el-col>
                    <el-col :span="8"><span class="gl_t">订单总价：</span>￥{{ order_info.total_price }}</el-col>
                    <el-col :span="8"><span class="gl_t">红包优惠：</span>￥{{ order_info.red_price }}</el-col>
                    <el-col :span="8"><span class="gl_t">实际付款：</span>￥{{ order_info.pay_price }}</el-col>
                    <el-col :span="24"><span class="gl_t">用户信息：</span>手机号：{{ order_info.user_info.mobile }},
                        昵称：{{ order_info.user_info.nickname }}</el-col>
                    <!-- <el-col :span="8"  ><span class="gl_t">时效保证金：</span>￥{{order_info.sub_obj.time_deposit}}</el-col>
                    <el-col :span="8" ><span class="gl_t">安全保证金：</span>￥{{order_info.sub_obj.safe_deposit}}</el-col> -->
                    <el-col :span="24" v-if="order_info.game_id == 1"><span class="gl_t">代练信息：</span>
                        <el-row v-if="order_info.sub_obj.hed_type == 1">
                            <el-col
                                :span="8">区服：{{ order_info.sub_obj.sub_type }}（{{ order_info.sub_obj.hed_type_name }}）</el-col>
                            <el-col :span="8">代练段位：{{ order_info.sub_obj.dai_duanwei }}</el-col>
                            <el-col :span="8">英雄数量：{{ order_info.sub_obj.yinxiong_num }}</el-col>
                            <el-col :span="8">铭文等级：{{ order_info.sub_obj.mingwendengji }}</el-col>
                        </el-row>
                        <el-row v-if="order_info.sub_obj.hed_type == 2">
                            <el-col
                                :span="8">区服：{{ order_info.sub_obj.sub_type }}（{{ order_info.sub_obj.hed_type_name }}）</el-col>
                            <el-col :span="8">英雄名称：{{ order_info.sub_obj.hero_name }}</el-col>
                            <el-col :span="8">当前段位：{{ order_info.sub_obj.duanwei }}</el-col>
                            <el-col :span="8">初始战力：{{ order_info.sub_obj.start_zhangli }}</el-col>
                            <el-col :span="8">目标战力：{{ order_info.sub_obj.end_zhangli }}</el-col>
                            <el-col :span="8">巅峰赛状态：{{ order_info.sub_obj.dfs_open }}</el-col>
                            <el-col :span="8">巅峰赛分数：{{ order_info.sub_obj.dfs_score }}</el-col>
                            <el-col :span="8">铭文等级：{{ order_info.sub_obj.mingwendengji }}</el-col>
                        </el-row>
                        <el-row v-if="order_info.hed_type == 3">
                            <el-col :span="8">区服：{{ order_info.sub_type }}（{{ order_info.hed_type_name }}）</el-col>
                            <el-col :span="8">初始分数：{{ order_info.sub_obj.start_score }}</el-col>
                            <el-col :span="8">目标分数：{{ order_info.sub_obj.end_score }}</el-col>
                            <el-col :span="8">英雄数量：{{ order_info.sub_obj.yinxiong_num }}</el-col>
                            <el-col :span="8">铭文等级：{{ order_info.sub_obj.mingwendengji }}</el-col>
                        </el-row>
                        <el-row v-if="order_info.sub_obj.hed_type == 4">
                            <el-col :span="8">区服：{{ order_info.sub_type }}（{{ order_info.hed_type_name }}）</el-col>
                            <el-col :span="8">英雄名称：{{ order_info.sub_obj.hero_name }}</el-col>
                            <el-col :span="8">国标等级：{{ order_info.sub_obj.mubiao_guo }}</el-col>
                            <el-col :span="8">战力值：{{ order_info.sub_obj.start_zhangli }}</el-col>
                            <el-col :span="8">巅峰赛状态：{{ order_info.sub_obj.dfs_open }}</el-col>
                            <el-col :span="8">巅峰赛分数：{{ order_info.sub_obj.dfs_score }}</el-col>
                            <el-col :span="8">铭文等级：{{ order_info.sub_obj.mingwendengji }}</el-col>
                        </el-row>
                    </el-col>
                    <el-col :span="24" v-if="order_info.game_id == 2"><span class="gl_t">代练信息：</span>
                        <el-row v-if="order_info.sub_obj.hed_type == 1">
                            <el-col
                                :span="8">区服：{{ order_info.sub_obj.sub_type }}（{{ order_info.sub_obj.hed_type_name }}）</el-col>
                            <el-col :span="8">第几人称：{{ order_info.sub_obj.rencheng }}</el-col>
                            <el-col :span="8">代练段位：{{ order_info.sub_obj.dai_duanwei }}</el-col>
                        </el-row>
                    </el-col>
                </el-row>
                <el-row v-if="order_info.dailian_status == 5" style="margin-top: 30px;">
                    <el-col :span="24">
                        <div class="gl_t" style="margin-bottom: 10px;">售后跟进记录</div>
                        <div v-if="followLoading" style="text-align:center;padding:40px 0;">
                            <el-spinner></el-spinner>
                        </div>
                        <div v-else
                            style="max-height:350px;overflow-y:auto;background:#fafbfc;border-radius:6px;padding:10px 16px;">
                            <el-timeline>
                                <el-timeline-item v-for="item in followList" :key="item.id"
                                    :timestamp="formatFollowTime(item.created_at)"
                                    :color="getFollowColor(item.user_type)">
                                    <p :style="{ color: getFollowColor(item.user_type), fontWeight: 'bold' }">
                                        {{ getUserTypeName(item.user_type) }}</p>
                                    <p>{{ item.describe }}</p>
                                    <div v-if="item.images">
                                        <img v-for="(img, idx) in splitImages(item.images)" :key="idx" :src="img"
                                            style="max-width:120px;max-height:120px;margin:5px 5px 5px 0;cursor:pointer;"
                                            @click="previewImg(img)" />
                                    </div>
                                </el-timeline-item>
                            </el-timeline>
                            <div v-if="!followList.length" style="text-align:center;color:#aaa;">暂无跟进记录</div>
                        </div>
                        <div style="margin-top:16px;display:flex;align-items:flex-end;gap:8px;">
                            <el-input type="textarea" v-model="followInput" :rows="5" placeholder="请输入回复内容"
                                style="flex:1" maxlength="200" show-word-limit />
                            <el-upload class="follow-upload-mini" ref="followUploads" :auto-upload="true"
                                :multiple="true" :show-file-list="true" accept="image/*"
                                :on-success="followUploadSuccess" :on-error="followUploadError"
                                :on-preview="followUploadPreview" :before-upload="beforeFollowAvatarUpload"
                                :action="api.upload_img_url" list-type="picture-card" :on-exceed="followUploadExceed"
                                :file-list="followImgFileList"
                                style="display:inline-block;width:auto;vertical-align:bottom;">
                                <el-button size="mini" icon="el-icon-upload"
                                    style="padding: 6px 10px;min-width: 60px;">上传图片</el-button>
                            </el-upload>
                        </div>
                        <div style="display: flex; justify-content: space-between;">
                            <el-button type="primary" :loading="followReplyLoading"
                                @click="submitFollowReply">回复</el-button>
                            <el-button type="danger" style="margin-left:8px;" @click="openArbitrateDialog">最终裁决</el-button>
                        </div>
                    </el-col>
                </el-row>
            </el-form>
            <!-- <span slot="footer" class="dialog-footer">
                <el-button @click="InfoVisible = false">关 闭</el-button>
            </span> -->
        </el-dialog>
        <!-- 编辑发货 -->
        <el-dialog title="编辑发货信息" v-dialogDrag :visible.sync="deliverVisible" width="580px">
            <el-form ref="edit" :model="deliver" label-width="90px">
                <el-form-item label="发货说明" class="form-item">
                    <el-input v-model="deliver.deliver_desc" maxlength="30" type="text" minlength="2"
                        placeholder="请输入发货说明,尽量字数控制20字以内"></el-input>
                </el-form-item>
                <el-form-item label="发货单号" class="form-item">
                    <el-input v-model="deliver.deliver_sn" maxlength="30" type="text" minlength="2"
                        placeholder="请输入发货单号,尽量不要填写无关内容"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="deliverVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveDeliver">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 售后跟进记录 -->
        <el-dialog title="售后跟进记录" :visible.sync="followVisible" width="600px">
            <div v-if="followLoading" style="text-align:center;padding:40px 0;">
                <el-spinner></el-spinner>
            </div>
            <div v-else>
                <el-timeline>
                    <el-timeline-item v-for="(item, idx) in followList" :key="idx" :timestamp="item.create_time">
                        <p>{{ item.content }}</p>
                        <p style="color:#888;font-size:12px;">操作人：{{ item.operator }}</p>
                    </el-timeline-item>
                </el-timeline>
                <div v-if="!followList.length" style="text-align:center;color:#aaa;">暂无跟进记录</div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="followVisible = false">关 闭</el-button>
            </span>
        </el-dialog>
        <el-dialog title="图片预览" :visible.sync="imgPreviewVisible" width="auto" top="5vh">
            <img :src="imgPreviewUrl" style="max-width:90vw;max-height:80vh;display:block;margin:auto;" />
        </el-dialog>
        <!-- 最终裁决弹窗 -->
        <el-dialog title="最终裁决" :visible.sync="arbitrateDialogVisible" width="500px">
            <el-form :model="arbitrateForm" :rules="arbitrateRules" ref="arbitrateForm" label-width="120px">
                <el-form-item label="扣除时效保证金" prop="deduct_time_deposit">
                    <el-input v-model.number="arbitrateForm.deduct_time_deposit" type="number" min="0" placeholder="请输入扣除时效保证金" style="width: 180px; display: inline-block;" />
                    <span style="margin-left: 10px; color: #888; font-size: 13px;">(总: ￥{{ order_info.sub_obj && order_info.sub_obj.time_deposit ? order_info.sub_obj.time_deposit : 0 }})</span>
                </el-form-item>
                <el-form-item label="扣除安全保证金" prop="deduct_safe_deposit">
                    <el-input v-model.number="arbitrateForm.deduct_safe_deposit" type="number" min="0" placeholder="请输入扣除安全保证金" style="width: 180px; display: inline-block;" />
                    <span style="margin-left: 10px; color: #888; font-size: 13px;">(总: ￥{{ order_info.sub_obj && order_info.sub_obj.safe_deposit ? order_info.sub_obj.safe_deposit : 0 }})</span>
                </el-form-item>
                <el-form-item label="退款给用户" prop="refund_user_money">
                    <el-input v-model.number="arbitrateForm.refund_user_money" type="number" min="0" placeholder="请输入退款给用户金额" style="width: 180px; display: inline-block;" />
                    <span style="margin-left: 10px; color: #888; font-size: 13px;">(实付: ￥{{ order_info.pay_price || 0 }})</span>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="arbitrateDialogVisible = false">取 消</el-button>
                <el-button type="primary" :loading="arbitrateLoading" @click="submitArbitrate">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>

export default {
    name: 'dl_game_order',
    data() {
        return {
            query: {
                page: 1,
                pageSize: 10,
                dailian_status: '',
                sort: '1',
                belong: 2
            },
            deliverVisible: false,
            InfoVisible: false,
            deliver: {}, order_info: { 'goods_info': { 'banner': '', 'name': '' }, 'user_info': { 'mobile': '', 'nickname': '' } },
            loading: false,
            tableData: [],
            multipleSelection: [],
            pageTotal: 0,
            delList: [],
            idx: -1,
            id: -1,
            followVisible: false,
            followList: [],
            followLoading: false,
            followDialogFromBtn: false,
            imgPreviewVisible: false,
            imgPreviewUrl: '',
            followInput: '',
            followReplyLoading: false,
            followImgUrl: '',
            followUploadLoading: false,
            followImgFileList: [], // 支持多图
            arbitrateDialogVisible: false,
            arbitrateForm: {
                deduct_time_deposit: 0,
                deduct_safe_deposit: 0,
                refund_user_money: 0
            },
            arbitrateRules: {
                deduct_time_deposit: [
                    { required: true, message: '请输入扣除时效保证金', trigger: 'blur' },
                    { type: 'number', min: 0, message: '不能为负数', trigger: 'blur' }
                ],
                deduct_safe_deposit: [
                    { required: true, message: '请输入扣除安全保证金', trigger: 'blur' },
                    { type: 'number', min: 0, message: '不能为负数', trigger: 'blur' }
                ],
                refund_user_money: [
                    { required: true, message: '请输入退款给用户金额', trigger: 'blur' },
                    { type: 'number', min: 0, message: '不能为负数', trigger: 'blur' }
                ]
            },
            arbitrateLoading: false,
            //获取列表请求
            getList: function () {
                let that = this;
                this.api.get('getGameOrder', this.query, res => {
                    for (let i in res.data.list) {
                        res.data.list[i].status = res.data.list[i].status + '';
                    }
                    that.tableData = res.data.list;
                    that.query.page = res.data.page;
                    that.query.pageSize = res.data.pageSize;
                    that.pageTotal = res.data.pageTotal;
                }, undefined, undefined, this);
            },
            //删除请求
            delLists: function (ids, msg) {
                let that = this;
                if (ids.length < 1) {
                    this.$message.error('请选择删除的数据');
                    return false;
                }
                // 二次确认删除
                this.$confirm('确定要删除吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    that.api.delete('delReport', { ids: ids }, res => {
                        that.query.page = 1;
                        that.getList();
                        that.multipleSelection = [];
                        that.$message.success(res.msg);
                    }, undefined, undefined, this);
                }).catch(() => { });
            }
        };
    },
    created() {
        this.getList();

    },
    methods: {
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'page', 1);
            this.getList();
        },
        exportSource() {
            this.api.exportExcel(document.querySelector('#repottable'), '兑换订单数据表')
        },
        handleSizeChange(val) {
            console.log(val)
            if (val == 0) {
                this.query.pageSize = 100000000;
            } else {
                this.query.pageSize = val;
            }
            this.getList();
        },
        getDailianStatusName(val) {
            const map = {
                0: '待支付',
                1: '待接单',
                2: '打手待支付',
                3: '进行中',
                4: '待确认',
                5: '售后',
                8: '已取消',
                9: '已完成'
            };
            return map[val] || val;
        },
        handleEdit(index, row, status) {
            let statusText = '';
            if (status == 1) statusText = '开始接单';
            else if (status == 4) statusText = '待确认';
            else statusText = '操作';
            this.$confirm('确定要' + statusText + '吗？', '提示', {
                type: 'warning'
            }).then(() => {
                this.api.put('dlOrderStatus', { id: row.id, dailian_status: status }, res => {
                    this.tableData[index].dailian_status = status;
                    this.$message.success(res.msg);
                    this.getList();
                });
            }).catch(() => { });
        },
        InfoView(index, row, fromFollowBtn) {
            this.order_info = row
            this.InfoVisible = true;
            this.followDialogFromBtn = !!fromFollowBtn;
            if (row.dailian_status == 5) {
                this.followLoading = true;
                this.followList = [];
                this.api.post('orderFollow-getOrderFollows', { order_id: row.id }, res => {
                    this.followList = Array.isArray(res.data) && Array.isArray(res.data[0]) ? res.data[0] : (res.data || []);
                    this.followLoading = false;
                }, err => {
                    this.followLoading = false;
                });
            } else {
                this.followList = [];
            }
        },
        formatFollowTime(ts) {
            if (!ts) return '';
            const d = new Date(ts * 1000);
            return d.getFullYear() + '-' + (d.getMonth() + 1).toString().padStart(2, '0') + '-' + d.getDate().toString().padStart(2, '0') + ' ' + d.getHours().toString().padStart(2, '0') + ':' + d.getMinutes().toString().padStart(2, '0');
        },
        getUserTypeName(type) {
            if (type == 1) return '平台';
            if (type == 2) return '用户';
            if (type == 3) return '代练打手';
            return '未知';
        },
        getFollowColor(type) {
            if (type == 1) return '#409EFF'; // 平台 蓝色
            if (type == 2) return '#67C23A'; // 用户 绿色
            if (type == 3) return '#E6A23C'; // 代练打手 橙色
            return '#909399';
        },
        /**
         * 复制文本
         */
        copy(text) {
            if (!text || text == '' || text == ' ') {
                this.$message.error('没有可复制的信息');
                return false;
            }
            this.$copyText(text).then(() => {
                this.$message.success('复制成功');
            }, () => {
                this.$message.error('复制失败，当前浏览器不支持复制');
            });
        },

        /**
         * 保存发货信息
         */
        saveDeliver() {
            this.api.put('report-deliver', this.deliver, res => {
                this.deliverVisible = false;
                this.$message.success('保存成功');
                this.getList();
            }, undefined, undefined, this);
        },

        showText(title, text) {
            this.$alert(text, title, {
                confirmButtonText: '确定',
                callback: action => {

                }
            });
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },

        // 删除操作
        handleDelete(index, row) {
            this.delLists([row.id], '删除成功');
        },
        //批量删除
        delAllSelection() {
            const length = this.multipleSelection.length;
            let str = '';
            this.delList = this.delList.concat(this.multipleSelection);
            let ids = [];
            for (let i = 0; i < length; i++) {
                str += this.multipleSelection[i].name + ' ';
                ids.push(this.multipleSelection[i].id);
            }
            this.delLists(ids, `删除了${str}`);
        },

        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'page', val);
            this.getList();
        },
        previewImg(url) {
            this.imgPreviewUrl = url;
            this.imgPreviewVisible = true;
        },
        followUploadSuccess(response, file, fileList) {
            if (response.code != 1000) {
                this.$message.error(response.msg);
                return false;
            }
            // 多图追加
            this.followImgFileList.push({ name: file.name, url: response.data.url });
            // 兼容旧逻辑，收集所有图片url
            this.followImgUrl = this.followImgFileList.map(f => f.url).join(',');
        },
        followUploadError(response, file, fileList) {
            this.$message.error('上传失败');
        },
        followUploadPreview(file) {
            this.imgPreviewUrl = file.url;
            this.imgPreviewVisible = true;
        },
        beforeFollowAvatarUpload(file) {
            const isLt2M = file.size / 1024 / 1024 < 5;
            if (!isLt2M) {
                this.$message.error('上传大小不能超过5MB');
            }
            return isLt2M;
        },
        followUploadExceed() {
            this.$message.error('最多上传9张图片');
        },
        removeFollowImg(file, fileList) {
            this.followImgFileList = fileList;
            this.followImgUrl = fileList.map(f => f.url).join(',');
        },
        submitFollowReply() {
            if (!this.followInput.trim()) {
                this.$message.warning('请输入回复内容');
                return;
            }
            this.followReplyLoading = true;
            this.api.post('orderFollow-addOrderFollow', {
                order_id: this.order_info.id,
                describe: this.followInput,
                images: this.followImgUrl,
                user_type: 1 // 平台，实际可根据登录身份调整
            }, res => {
                this.followInput = '';
                this.followImgFileList = [];
                this.followImgUrl = '';
                this.followReplyLoading = false;
                this.$message.success('回复成功');
                // 重新拉取跟进记录
                this.InfoView(null, this.order_info, this.followDialogFromBtn);
            }, err => {
                this.followReplyLoading = false;
            });
        },
        openArbitrateDialog() {
            this.arbitrateForm = {
                deduct_time_deposit: 0,
                deduct_safe_deposit: 0,
                refund_user_money: 0
            };
            this.arbitrateDialogVisible = true;
        },
        submitArbitrate() {
            this.$refs.arbitrateForm.validate(valid => {
                if (!valid) return;
                this.arbitrateLoading = true;
                this.api.post('dailian-appealAribtrateFinish', {
                    id: this.order_info.id,
                    deduct_time_deposit: this.arbitrateForm.deduct_time_deposit,
                    deduct_safe_deposit: this.arbitrateForm.deduct_safe_deposit,
                    refund_user_money: this.arbitrateForm.refund_user_money
                }, res => {
                    this.arbitrateLoading = false;
                    this.arbitrateDialogVisible = false;
                    this.$message.success('裁决完成');
                    // 重新拉取跟进记录和订单信息
                    this.InfoView(null, this.order_info, this.followDialogFromBtn);
                }, err => {
                    this.arbitrateLoading = false;
                });
            });
        },
        splitImages(images) {
            if (!images) return [];
            return images.split(',').filter(Boolean);
        },
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 150px;
}

.show-text {
    cursor: pointer;
    color: #75c0ed;
}

.show-text:hover {
    color: #2e91cd;
}

.handle-input {
    width: 300px;
    display: inline-block;
}

.table {
    width: 100%;
    font-size: 14px;
}

.red {
    color: #ff0000;
}

.mr10 {
    margin-right: 10px;
}

.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}

.gl_t {
    font-weight: bold;
}

.follow-upload-mini {
    min-width: 60px;
    width: auto;
    display: inline-block;
    vertical-align: bottom;
}

.follow-upload-mini .el-upload {
    min-width: 60px;
    padding: 0;
}

.follow-upload-mini .el-upload-list {
    margin: 0 0 0 4px;
    padding: 0;
}
</style>
